package com.wframe.project.former.web.floor;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.frame.pageform.DataPageForm;
import com.frame.pageform.annotation.Login;
import com.wframe.project.former.dataservices.floor.FloorService;

/**
 * 楼层管理
 * @author lenovo
 *
 */
@Login
public class FloorPage extends DataPageForm{

	private FloorService floorService=FloorService.getIntance();
	private JdataBean bean;
	
	@Override
	public String execute() throws Exception {
		setResultList_(floorService.queryFloors(bean));
		return "/webadmin/floor/floorList.jsp";
	}
	
	@Override
	public String show() throws Exception {
		// TODO Auto-generated method stub
		bean=floorService.getBean(bean.getString("id"));
		return "/webadmin/floor/floorEdit.jsp";
	}

	@Override
	public String toDel() throws Exception {
		return getJsonObject().toString();
	}

	@Override
	public boolean toUpdate() throws Exception {
		// TODO Auto-generated method stub
		Map key=new HashMap();
		key.put("id", bean.getString("id"));
		floorService.update(bean.getDataMap(),key);
		getJsonObject().getJsonPage().showOkMsg("修改成功");
		getJsonObject().getJsonPage().closeWin("ok");
		return false;
	}
	
	public String floorCategory() throws Exception{
		setResultList_(floorService.queryFloorItem(bean.getString("floorid")));
		return "/webadmin/floor/floorCategory.jsp";
	}

	public String floorCategoryShow() throws Exception{
		if(bean!=null && StringUtils.isNotBlank(bean.getString("id")))
			bean=floorService.getFloorItem(bean.getString("id"));
		return "/webadmin/floor/floorCategoryEdit.jsp";
	}
	public String floorCategorSave() throws Exception{
		String[] proids=null;
		if(StringUtils.isNotBlank(bean.getString("proids")))proids=bean.getString("proids").split(",");
		bean.remove("proids");
		floorService.saveFloorItem(bean, proids);
		getJsonObject().getJsonPage().showOkMsg("保存成功");
		getJsonObject().getJsonPage().closeWin("ok");
		return getJsonObject().toString();
	}
	public String floorCategorDel() throws Exception{
		floorService.delFloorItem(bean.getString("id"));
		return getJsonObject().toString();
	}
	public String loadFloorProducts() throws Exception{
		int pageno=1;
		int size=20;
		if(StringUtils.isNotBlank(getRequest().getParameter("page")))pageno=new Integer(getRequest().getParameter("page"));
		if(StringUtils.isNotBlank(getRequest().getParameter("rows")))size=new Integer(getRequest().getParameter("rows"));
		PageResult pr=floorService.queryFloorProduct(bean, size,pageno);
		getJsonObject().put("total",pr.getResultCount());
    	getJsonObject().put("rows", pr.getList());
    	return getJsonObject().toString();
	}
	public String updatestatus() throws Exception{
		if(getPrimaryKey_()!=null){
			for(String id:getPrimaryKey_()){
				floorService.updatestatus(id,bean.getInt("status"));
			}
		}
		return getJsonObject().toString();
	}
	public JdataBean getBean() {
		return bean;
	}

	public void setBean(JdataBean bean) {
		this.bean = bean;
	}
	
}
